%--------------------------------------------------------------------------
%Smoothing Quadratic Regularization Methods for Non-Lipschitzian
%Optimization

%Solve
%          min   f(x):= H(x)+ \sum_{i=1}^n \phi(|x_i|^p), x \in R^n
%          
%This file uses SQR algorithm to solve example 5.1 in the reference 
%"Worst-case Complexity of Smoothing Quadratic Regularization Methods for 
%Non-Lipschitzian Optimization" to show how to use SQR algorithm to solve
% a class of Non-Lipschitzian optimization mentioned in the above
% reference.
%--------------------------------------------------------------------------
%Notation:
%   A: a 2 by 1 matrix, used to define function H(x)
%   b: a scalar, also used to define function H(x)
%   p: a constant that satisfies 0<p<=1, used to define the objective function
%      phi
%   lambda: a constant, used to define penalty function
%   The rest are the same with those mentioned in "SQR_Nonlip.m" file
%--------------------------------------------------------------------------
clear all; clc;

global A b lambda   %set as global variable so as to define other functions

%Input data
A=[1 1];
b=1;

lambda=8/(3*sqrt(3));
%lambda=1;

p=0.5;
eps=1e-4;

sigma=0.9;
sigma1=0.9;
sigma2=0.9;
eta=2;
beta0=1;
beta1=2*norm(A'*A);
mu0=10;
alpha=lambda;


%use SQR algorithm to solve the Non-Lipschitz optimization   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%--------------------------------------------------------------------------

for i=1:10
    x0(:,i)=rand(2,1);  % use rand to generate a random vector as the initial point
    t=cputime;
    Out(i)=SQR_NonLip(x0(:,i),mu0,beta0,beta1,sigma,sigma1,sigma2,eta,alpha,p,eps);
    t=cputime-t;
    fprintf('\n');
    fprintf(' The costed cputime is:%d\n',t);
end
%--------------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


